package com.ww.learn.generic

fun main() {
    // 逆变反转子类型关系
    val animalConsumer: Consumer<Animal> = AnimalConsumer()
    val dogConsumer: Consumer<Dog> = animalConsumer // 逆变
    val puppyConsumer: Consumer<Puppy> = dogConsumer // 逆变

    // Animal consumer handling: tiny
    puppyConsumer.consume(Puppy("tiny"))

    // 更复杂的逆变示例
    val generalConsumer: Consumer<Any> = GeneralConsumer()
    val anyAnimalConsumer: Consumer<Animal> = generalConsumer // 逆变
    // General consumer handling: com.ww.learn.generic.Dog@79fc0f2f
    anyAnimalConsumer.consume(Dog("Rex"))
}